package com.cysion.study.adapter

import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.cysion.study.R
import com.cysion.study.entity.POrderListEntity
import com.cysion.study.ktbox.base.BaseAdapter
import com.cysion.study.ktbox.base.BaseViewHolder
import com.cysion.study.ktbox.base.ITEM_CLICK
import kotlinx.android.synthetic.main.item_p_order.view.*

class POrderChildFragmentAdapter(mEntities: MutableList<POrderListEntity>, mContext: Context) :
    BaseAdapter<POrderListEntity>(mEntities, mContext) {
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): BaseViewHolder<POrderListEntity> {

        return ProMoneyHolder(
            LayoutInflater.from(mContext).inflate(R.layout.item_p_order, parent, false)
        )
    }

    class ProMoneyHolder(itemView: View) : BaseViewHolder<POrderListEntity>(itemView) {
        override fun fillData(obj: POrderListEntity, position: Int) {
            itemView?.apply {
                itemView.tv_name.text = obj.title
                itemView.tv_time.text = "预约有效时间："+obj.feduValidEndTime
                itemView.tv_create_time.text = obj.createTime

                ////订单状态：0.待付款 1.已付款 2.已完成（已评价）3、待评价 4.申请退款中，5.已拒绝退款，
                // 6.已同意退款 7.交易关闭，8、申请客服介入中； 9、客服同意退款 10、客服拒绝退款
                // 11、原路退回中，12、原路退款成功 13、原路退款失败，14、家教订单待确认；
                if (obj.status == "0") {
                    if (!TextUtils.isEmpty(obj.payMoney)) {
                        if (obj.payMoney.toDouble() > 0) {
                            itemView.tv_status.text = "课程数量：" + obj.quanty + "节"
                            itemView.tv_time.text = "预约状态：" + "服务中"
                            itemView.tv_money.text = " ￥" + obj.payMoney
                            itemView.tv_money.visibility = View.VISIBLE
                        } else {
                            itemView.tv_time.visibility = View.GONE
                            itemView.tv_status.text = "待付款"
                        }
                    } else {
                        itemView.tv_time.visibility=View.GONE
                        itemView.tv_status.text = "待付款"
                    }
                } else if (obj.status == "1") {
                    itemView.tv_status.text = "服务中"
                } else if (obj.status == "2") {
                    itemView.tv_status.text = "已完成"
                } else if (obj.status == "3") {
                    itemView.tv_status.text = "待评价"
                } else if (obj.status == "4") {
                    itemView.tv_status.text = "申请退款中"
                } else if (obj.status == "5") {
                    itemView.tv_status.text = "已拒绝退款"
                } else if (obj.status == "6") {
                    itemView.tv_status.text = "已同意退款"
                } else if (obj.status == "7") {
                    itemView.tv_status.text = "交易关闭"
                }else if (obj.status == "8") {
                    itemView.tv_status.text = "申请客服介入中"
                }else if (obj.status == "9") {
                    itemView.tv_status.text = "客服同意退款"
                }else if (obj.status == "10") {
                    itemView.tv_status.text = "客服拒绝退款"
                }else if (obj.status == "11") {
                    itemView.tv_status.text = "原路退回中"
                }else if (obj.status == "12") {
                    itemView.tv_status.text = "原路退款成功"
                }else if (obj.status == "13") {
                    itemView.tv_status.text = "原路退款失败"
                }else if (obj.status == "14") {
                    itemView.tv_status.text = "待确认"
                    tv_money.visibility=View.GONE
                }


                itemView.setOnClickListener {
                    mOnTypeClickListener?.invoke(obj, position, ITEM_CLICK)
                }

            }

        }

    }

}



